import {
  Column,
  PrimaryGeneratedColumn,
  Entity,
  OneToOne,
  OneToMany,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { IdCard } from '../../id-card/entities/id-card.entity';
import { Job } from '../../job/entities/job.entity';
import { Tag } from '../../tag/entities/tag.entity';
import { Exclude, Expose } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

@Entity()
export class User {
  @ApiProperty()
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty()
  @Column()
  name: string;

  @ApiProperty()
  @Exclude()
  @Column()
  desc: string;

  @ApiProperty()
  @Expose()
  get sum(): string {
    return `${this.name}, ${this.desc}`;
  }

  @Exclude()
  @Column({
    length: 50,
    comment: '密码',
  })
  password: string;

  @ApiProperty()
  @Expose()
  @Column({
    length: 50,
    comment: '邮箱地址',
  })
  email: string;

  @ApiProperty({ type: [Number] })
  @OneToOne(() => IdCard, (idCard) => idCard.userId)
  idCard: IdCard;

  @ApiProperty({ type: [Number] })
  @OneToMany(() => Job, (job) => job.userId)
  jobIds: Job[];

  @Exclude()
  @ApiProperty({ type: [Number] })
  @JoinTable({ name: 'user_tag' })
  @ManyToMany(() => Tag, (tag) => tag.users)
  tags: Tag[];

  // constructor(partial: Partial<User>) {
  //   Object.assign(this, partial);
  // }
}
